<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %>

<html>
	<head>
		<title>Connection with mysql database</title> 
	</head> 
	<body>
	<h1>Connection status</h1>
	<% 
	try {
		/* Create string of connection url within specified format with machine name, port number and database name. Here machine name id localhost and  database name is sampledb. */ 
		String connectionURL = "jdbc:mysql://localhost:3306/edcom"; 

		/* declare a connection by using Connection interface */
		Connection connection = null; 

		/* Load JDBC driver "com.mysql.jdbc.Driver" */
		Class.forName("com.mysql.jdbc.Driver").newInstance(); 

		/* Create a connection by using getConnection() method that takes parameters of string type connection url, user name and password to connect to database. */ 
		connection = DriverManager.getConnection(connectionURL, "root", "1234");

		/* check weather connection is established or not by isClosed() method? */
		if(!connection.isClosed()) %> <font size="+3" color="green"></b> <% 
			out.println("Successfully connected to " + "MySQL server using TCP/IP...");
			connection.close();
	}
	catch (SQLException sqle){ %></font> <font size="+3" color="red"></b> <%
		out.println("Unable to connect to database. <br/>SQLE> ");
		out.println(sqle.getMessage());
	}
	catch(Exception ex){ %></font> <font size="+3" color="red"></b> <%
		out.println("Unable to connect to database. <br/>EX> ");
		out.println(ex.getMessage());
	}
	%> </font>
	<br/>
	<!-- RealPath{<%= request.getRealPath("/") %>} -->
	</body> 
</html> 
